<%=javascript_include_tag :defaults %>
<style>
.regionLeft {
  float: left;
}
.regionTop {
  background: pink;
}
.regionRight {
  float: right;
}
.regionBottom {
  background: lightblue;
}
</style>
<h1>Teams for <%=@pool.name%></h1>
<p>
<i>Same color region champs play each other in final four:</i>
</p>
<p>
Order: <%= button_to_function('Seed Order', 'switch_to_seed_order()', :id => 'seed_button', :disabled => true) %> <%= button_to_function('Matchup Order', 'switch_to_matchup_order()', :id => 'matchup_button')%>
</p>
<%= form_tag({:controller => 'teams', :action => 'change', :id => @pool.id}, {:method => "POST"}) %>
<% @pool.region_seedings.each_with_index do |arr, index| -%>
<% region_name = arr[0]; teams = arr[1] %>
<div class="<%= cycle('regionLeft', 'regionRight', :name => 'tbclass')%> <%= cycle('regionTop', 'regionTop', 'regionBottom', 'regionBottom', :name => 'lrclass')%>">
Region Name: <input type="text" name="region<%=index%>[name]" value="<%=region_name%>">
<table id="<%="region_#{index}"%>">
<tr>
<th>Seed</th>
<th>Name</th>
<th>Short<br/>Name</th>
</tr>
<% teams.each_with_index do |team, seed_idx| -%>
<tr id="<%="region_#{index}_#{seed_idx}"%>">
<td>
<%= seed_idx + 1%>
</td>
<td>
<input type="text" autocomplete="false" id="team_name_<%=index%>_<%=seed_idx%>" name="region<%=index%>[seedings][][name]" value="<%=team ? team.name : ''%>">
<%=content_tag("div", "", :id => "team_name_#{index}_#{seed_idx}_auto_complete", :class => "auto_complete") %>
<%= auto_complete_field "team_name_#{index}_#{seed_idx}", :url => { :action => 'auto_complete_for_team_name'},
    :after_update_element => 'function(element, value) {short_id = element.id.replace("team_name", "short_name"); $(short_id).value = value.readAttribute("short")}'
%>
</td>
<td>
<input type="text" autocomplete="false" id="short_name_<%=index%>_<%=seed_idx%>" size="5" maxlength="3" name="region<%=index%>[seedings][][short_name]" value="<%= team ? team.short_name : ''%>">
<%=content_tag("div", "", :id => "short_name_#{index}_#{seed_idx}_auto_complete", :class => "auto_complete") %>
<%= auto_complete_field "short_name_#{index}_#{seed_idx}", :url => { :action => 'auto_complete_for_short_name'},
    :after_update_element => 'function(element, value) {name_id = element.id.replace("short_name", "team_name"); $(name_id).value = value.readAttribute("name")}'
%>
</td>
<input type="hidden" name="region<%=index%>[seedings][][seed]" value="<%=seed_idx + 1%>">
</tr>
<% end -%>
</table>
</div>
<% end -%>
<input type="submit" value="Save"/>
</form>
